package sbc.group1.lab1.mozartspaces;

import java.awt.EventQueue;
import java.io.File;
import java.net.URI;
import java.net.URL;

import javax.swing.JFrame;

import org.mozartspaces.core.MzsCoreException;

public class FactoryGui {

    private JFrame frame;
    private SpaceClient space;

    /**
     * Launch the application.
     */
    public static void main(final String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    FactoryGui window = new FactoryGui(new File(args[0]).toURI().toURL(), new URI(args[1]));
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     * @throws InterruptedException 
     * @throws MzsCoreException 
     */
    public FactoryGui(URL configFile, URI spaceURI) throws MzsCoreException, InterruptedException {
        space = new SpaceClient();
        space.init(configFile, spaceURI);
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     * @throws InterruptedException 
     * @throws MzsCoreException 
     */
    private void initialize() throws MzsCoreException, InterruptedException {
        frame = new JFrame();
        frame.getContentPane().add(new FactoryPanel(space));
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}
